<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>reverse.exw</title>
<meta name="Generator" content="SciTE - www.Scintilla.org" />
<script language="JavaScript" type="text/javascript">
<!--
function symbol(id, sym) {
 if (id.textContent==undefined) {
 id.innerText=sym; } else {
 id.textContent=sym; }
}
function toggle(id) {
var thislayer=document.getElementById('ln'+id);
id-=1;
var togline=document.getElementById('hd'+id);
var togsym=document.getElementById('bt'+id);
if (thislayer.style.display == 'none') {
 thislayer.style.display='block';
 togline.style.textDecoration='none';
 symbol(togsym,'- ');
} else {
 thislayer.style.display='none';
 togline.style.textDecoration='underline';
 symbol(togsym,'+ ');
}
}
//-->
</script>
<style type="text/css">
.S0 {
	color: #808080;
}
.S2 {
	color: #007F7F;
}
.S4 {
	color: fore:#330033;
	background: #f0fff0;
	text-decoration: inherit;
}
.S8 {
	font-weight: bold;
	color: #000000;
}
.S10 {
	font-weight: bold;
	color: #00007F;
}
.S12 {
	color: #156CC4;
}
.S13 {
	color: #C29C00;
}
.S14 {
	color: #519D6C;
}
span {
	color: #000000;
	font-size: 14pt;
}
</style>
</head>
<body bgcolor="#FFFFFF">
<span>&nbsp; <span class="S10">global</span><span class="S0"> </span><span class="S10">object</span><span class="S0"> _ </span><span class="S8">=</span><span class="S0"> </span><span class="S2">0</span><br />
&nbsp; <br />
&nbsp; <span class="S10">include</span><span class="S0"> </span>std<span class="S8">/</span>io.e<br />
&nbsp; <span class="S10">include</span><span class="S0"> </span>std<span class="S8">/</span>sequence.e<br />
&nbsp; <br />
&nbsp; <span class="S10">include</span><span class="S0"> </span>qt<span class="S8">/</span>core.e<span class="S0"> </span><span class="S10">as</span><span class="S0"> </span>q<br />
&nbsp; <br />
&nbsp; <span class="S0">_ </span><span class="S8">=</span><span class="S0"> </span>q<span class="S0">:</span>init<span class="S8">()</span><br />
&nbsp; <br />
&nbsp; <span class="S10">integer</span><span class="S0"> </span>steps<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S8">-</span><span class="S2">1</span><br />
&nbsp; <span class="S10">sequence</span><span class="S0"> </span>gboard<span class="S8">={</span><span class="S2">1</span><span class="S8">,</span><span class="S2">2</span><span class="S8">,</span><span class="S2">3</span><span class="S8">,</span><span class="S2">4</span><span class="S8">,</span><span class="S2">5</span><span class="S8">,</span><span class="S2">6</span><span class="S8">,</span><span class="S2">7</span><span class="S8">,</span><span class="S2">8</span><span class="S8">,</span><span class="S2">9</span><span class="S8">},</span><span class="S0"> </span>board<span class="S8">=</span>shuffle<span class="S8">(</span>gboard<span class="S8">)</span><br />
&nbsp; <span class="S10">atom</span><span class="S0"> </span>win<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span>q<span class="S0">:</span>loadUI<span class="S8">(</span>read_file<span class="S8">(</span><span class="S4">"reverse.ui"</span><span class="S8">)),</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>moveCounter<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"moveCounter"</span><span class="S8">)</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; set_icon<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"eu4.png"</span><span class="S8">)</span><br />
<span id="hd15" onclick="toggle('16')"><span id="bt15">- </span><span class="S10">sequence</span><span class="S0"> </span>buttons<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S8">{</span></span><br />
<span id="ln16">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b1"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b2"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b3"</span><span class="S8">),</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b4"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b5"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b6"</span><span class="S8">),</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b7"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b8"</span><span class="S8">),</span><span class="S0"> </span>q<span class="S0">:</span>findChild<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"b9"</span><span class="S8">)</span><br />
&nbsp; <span class="S8">}</span><br /></span>
&nbsp; <br />
<span id="hd21" onclick="toggle('22')"><span id="bt21">- </span><span class="S10">procedure</span><span class="S0"> </span>UpdateBoard<span class="S8">(</span><span class="S10">integer</span><span class="S0"> </span>count<span class="S8">)</span></span><br />
<span id="ln22">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>board<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S13">reverse</span><span class="S8">(</span>board<span class="S8">,</span><span class="S0"> </span><span class="S2">1</span><span class="S8">,</span><span class="S0"> </span>count<span class="S8">)</span><br />
&nbsp; <br />
<span id="hd24" onclick="toggle('25')"><span id="bt24">- </span><span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">for</span><span class="S0"> </span>i<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S2">1</span><span class="S0"> </span><span class="S10">to</span><span class="S0"> </span>count<span class="S0"> </span><span class="S10">do</span></span><br />
<span id="ln25">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>propset<span class="S8">(</span>buttons<span class="S8">[</span>i<span class="S8">],</span><span class="S0"> </span><span class="S4">"text"</span><span class="S8">,</span><span class="S0"> </span><span class="S12">sprintf</span><span class="S8">(</span><span class="S4">"%d"</span><span class="S8">,</span><span class="S0"> </span>board<span class="S8">[</span>i<span class="S8">]))</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">end</span><span class="S0"> </span><span class="S10">for</span><br /></span>
&nbsp; <br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>steps<span class="S0"> </span><span class="S8">+=</span><span class="S0"> </span><span class="S2">1</span><br />
&nbsp; <br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>propset<span class="S8">(</span>moveCounter<span class="S8">,</span><span class="S0"> </span><span class="S4">"text"</span><span class="S8">,</span><span class="S0"> </span><span class="S12">sprintf</span><span class="S8">(</span><span class="S4">"Move #%d"</span><span class="S8">,</span><span class="S0"> </span>steps<span class="S8">))</span><br />
&nbsp; <br />
<span id="hd32" onclick="toggle('33')"><span id="bt32">- </span><span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">if</span><span class="S0"> </span><span class="S12">equal</span><span class="S8">(</span>gboard<span class="S8">,</span><span class="S0"> </span>board<span class="S8">)</span><span class="S0"> </span><span class="S10">then</span></span><br />
<span id="ln33"><span id="hd33" onclick="toggle('34')"><span id="bt33">- </span><span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _ </span><span class="S8">=</span><span class="S0"> </span>q<span class="S0">:</span>information<span class="S8">(</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"Winner"</span><span class="S8">,</span></span><br />
<span id="ln34">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S12">sprintf</span><span class="S8">(</span><span class="S4">"You've won in %d moves!"</span><span class="S8">,</span><span class="S0"> </span>steps<span class="S8">))</span><br /></span>
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S12">abort</span><span class="S8">(</span><span class="S2">0</span><span class="S8">)</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">end</span><span class="S0"> </span><span class="S10">if</span><br /></span>
&nbsp; <span class="S10">end</span><span class="S0"> </span><span class="S10">procedure</span><br /></span>
&nbsp; <br />
<span id="hd39" onclick="toggle('40')"><span id="bt39">- </span><span class="S10">function</span><span class="S0"> </span>OnQuit<span class="S8">()</span></span><br />
<span id="ln40"><span id="hd40" onclick="toggle('41')"><span id="bt40">- </span><span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">if</span><span class="S0"> </span><span class="S2">1</span><span class="S0"> </span><span class="S10">then</span></span><br />
<span id="ln41">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S12">abort</span><span class="S8">(</span><span class="S2">0</span><span class="S8">)</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">end</span><span class="S0"> </span><span class="S10">if</span><br /></span>
&nbsp; <br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">return</span><span class="S0"> </span><span class="S2">1</span><br />
&nbsp; <span class="S10">end</span><span class="S0"> </span><span class="S10">function</span><br /></span>
&nbsp; q<span class="S0">:</span>connect<span class="S8">({</span>win<span class="S8">,</span><span class="S0"> </span><span class="S4">"quit"</span><span class="S8">},</span><span class="S0"> </span><span class="S4">"clicked()"</span><span class="S8">,</span><span class="S0"> </span><span class="S4">"slot()"</span><span class="S8">,</span><span class="S0"> </span><span class="S12">routine_id</span><span class="S8">(</span><span class="S4">"OnQuit"</span><span class="S8">))</span><br />
&nbsp; <br />
<span id="hd48" onclick="toggle('49')"><span id="bt48">- </span><span class="S10">function</span><span class="S0"> </span>OnButton<span class="S8">(</span><span class="S10">atom</span><span class="S0"> </span><span class="S14">button</span><span class="S8">)</span></span><br />
<span id="ln49">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>UpdateBoard<span class="S8">(</span>eu<span class="S0">:</span><span class="S12">find</span><span class="S8">(</span><span class="S14">button</span><span class="S8">,</span><span class="S0"> </span>buttons<span class="S8">))</span><br />
&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">return</span><span class="S0"> </span><span class="S2">1</span><br />
&nbsp; <span class="S10">end</span><span class="S0"> </span><span class="S10">function</span><br /></span>
&nbsp; <span class="S10">constant</span><span class="S0"> </span>hOnButton<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S12">routine_id</span><span class="S8">(</span><span class="S4">"OnButton"</span><span class="S8">)</span><br />
&nbsp; <br />
<span id="hd54" onclick="toggle('55')"><span id="bt54">- </span><span class="S10">for</span><span class="S0"> </span>i<span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S2">1</span><span class="S0"> </span><span class="S10">to</span><span class="S0"> </span><span class="S2">9</span><span class="S0"> </span><span class="S10">do</span></span><br />
<span id="ln55">&nbsp; <span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span>q<span class="S0">:</span>connect<span class="S8">(</span>buttons<span class="S8">[</span>i<span class="S8">],</span><span class="S0"> </span><span class="S4">"clicked()"</span><span class="S8">,</span><span class="S0"> </span><span class="S4">"slotWidget()"</span><span class="S8">,</span><span class="S0"> </span>hOnButton<span class="S8">)</span><br />
&nbsp; <span class="S10">end</span><span class="S0"> </span><span class="S10">for</span><br /></span>
&nbsp; <br />
&nbsp; UpdateBoard<span class="S8">(</span><span class="S2">9</span><span class="S8">)</span><br />
&nbsp; <br />
&nbsp; q<span class="S0">:</span>show<span class="S8">(</span>win<span class="S8">)</span><br />
&nbsp; <span class="S0">_ </span><span class="S8">=</span><span class="S0"> </span>q<span class="S0">:</span>run<span class="S8">()</span><br />
&nbsp; <span class="S0"></span></span>
</body>
</html>
